package com.wish.nettyprotocol.struct;

import java.util.HashMap;
import java.util.Map;

/**
 * @author tantexian
 * @since 2016/7/17
 */
public final class Header {
    // 消息校验码，三部分组成：1-固定值2字节0xabef表示netty协议 2-主版本号1字节 3-次版本号1字节
    private int crcCode = 0xabef0101;
    private int length; // 整个消息长度（包括消息头，及消息体）
    private long sessionId;
    // 消息类型 0-业务请求消息 1-业务响应消息 3-握手请求消息 4-握手应答消息 5-心跳请求消息 6-心跳应答消息
    private byte type;
    private byte priority; // 消息优先级（0~255）
    // 可选字段，用于扩展消息头
    private Map<String, Object> attachment = new HashMap<String, Object>();

    public int getCrcCode() {
        return crcCode;
    }

    public void setCrcCode(int crcCode) {
        this.crcCode = crcCode;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public long getSessionId() {
        return sessionId;
    }

    public void setSessionId(long sessionId) {
        this.sessionId = sessionId;
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public byte getPriority() {
        return priority;
    }

    public void setPriority(byte priority) {
        this.priority = priority;
    }

    public Map<String, Object> getAttachment() {
        return attachment;
    }

    public void setAttachment(Map<String, Object> attachment) {
        this.attachment = attachment;
    }

    @Override
    public String toString() {
        return "Header{" +
                "crcCode=" + crcCode +
                ", fileSize=" + length +
                ", sessionId=" + sessionId +
                ", type=" + type +
                ", priority=" + priority +
                ", attachment=" + attachment +
                '}';
    }
}
